import { getDataBaseList } from '@/api/test/index';
import { postDataBase, handDataBase } from '@/pages/CodeTables/specification';
import { CodeTableStatus, stopwatchColor } from '@/enums/statusEnum';
const tableData = reactive<postDataBase>({
  dsmName: '',
  dsmStatus: undefined,
  pageNum: 1,
  pageSize: 20,
  total: 20,
});
const data = ref<handDataBase>();
const loading = ref<boolean>(false);
// 得到List数据
const getList = async () => {
  loading.value = true;
  try {
    const res = await getDataBaseList(tableData);
    console.log(res.records);

    res.records.forEach((item: handDataBase) => {
      item.updateTime = new Date(item.updateTime).toLocaleString();
      // 向后端请求数据对象中添加了statusColor用于控制状态颜色
      item.statusColor = stopwatchColor[+item.dsmStatus];
      item.dsmStatus = CodeTableStatus[+item.dsmStatus];
    });
    data.value = res.records as handDataBase;
    tableData.total = res.total;
    loading.value = false;
  } catch (error) {
    loading.value = false;
  }
};
export function getDataBaseListHooks() {
  return {
    getList,
    data,
    tableData,
    loading,
  };
}
